/*
** Code cache for shared function prototypes.
** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice in luajit.h
*/

#ifndef _LJ_CODECACHE_H
#define _LJ_CODECACHE_H

#include "lj_obj.h"

/* -- Code cache structures ----------------------------------------------- */

/* Simple cache using dedicated lua_State */
typedef struct CodeCache {
  lua_State *cache_L;
#if LJ_HASFFI
  void *lock;
#endif
} CodeCache;

/* Global code cache */
LJ_DATA CodeCache lj_codecache_global;

/* -- Code cache API ------------------------------------------------------ */

/* Initialize global code cache */
LJ_FUNC void lj_codecache_init(void);

/* Cleanup global code cache */
LJ_FUNC void lj_codecache_free(void);

/* Try to load from cache and clone to target state */
LJ_FUNC int lj_codecache_loadfile(lua_State *L, const char *filename, const char *mode);

LJ_FUNC lua_State *get_codecache_state();

#endif
